package models;

import java.util.*;

import javax.persistence.*;

import play.db.ebean.*;
import play.data.format.*;
import play.data.validation.*;


/**
 * User entity managed by Ebean
 */
@Entity
@Table(name="speciality")
public class Specialities extends Model {

	public static final long serialVersionUID = 1L;

	@Id
	@Column(name="idspeciality")
	public Long id;

    @Column(name="speciality")
    public String speciality;

    @Column(name="description")
    public String description;

    @Column(name="keywords")
    public String keywords;

    // -- Queries

    public static Model.Finder<String,Specialities> find = new Model.Finder(String.class, Specialities.class);

    public static List<Specialities> getAllSpecialities() {    
    	return find.all();
    }
    
    public static Specialities getSpeciality(long specialityId) {    
        return find.where()
                .eq("id", specialityId)
                .findUnique();
    }
    
    public static Specialities getSpecialityByName(String speciality) {    
        return find.where()
                .eq("speciality", speciality)
                .findUnique();
    }
    
    public static Specialities getSpecialityByKeyword(String keyword) {    
        return find.where()
                .like("keywords", "%"+keyword+"%")
                .findUnique();
    }
    
    public static List<Specialities> getSpecialities(String query,String keyword) {   
    	List<Specialities> specilities = new ArrayList<Specialities>();
    	if(null == keyword){
    		 specilities=find.where()
    	                .like("speciality", "%"+query+"%")
    	                .findList();
    	}else if(null == query){
    		 specilities=find.where()
  	                .like("keywords", "%"+keyword+"%")
  	                .findList();
    	}else{
     		 specilities=find.where()
 	                .like("keywords", "%"+keyword+"%")
 	                .like("speciality", "%"+query+"%")
 	                .findList();
    	}
        return specilities;
    }


}

